<?php
namespace Think;
class MultiThread  extends \Thread
{
    public $url;
    public $data;
    
    public function __construct($url)
    {
        $this->url = $url;
    }
    
    public function run()
    {
        if($url = $this->url){
            $this->data = json_decode($this->model_http_curl_get($url),true);
        }
    }
    
    //curl 获取数据
    public function model_http_curl_get($url, $userAgent = "")
    {
        $userAgent = $userAgent ? $userAgent : 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2)';
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_TIMEOUT, 5);
        //在访问https的时候加上下面那两行
        if(strpos($url, "https") !== false){
            date_default_timezone_set('PRC');
            curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);//终止从服务器端进行验证
        }
        curl_setopt($curl, CURLOPT_USERAGENT, $userAgent);
        $result = curl_exec($curl);
        curl_close($curl);
        
        return $result;
    }
    
}